package lex.dm.id3;

public class ArrayDataSet implements IDataSet {
	private final Object[][] dataSet;
	private final String[] attributes;
	private final int classAttrIndex;
	private static ArrayDataSet sample = null;

	public static void main(String[] args) {
		DataSetUtils.dump(ArrayDataSet.getSampleDataSet(), System.out);
	}

	public static ArrayDataSet getSampleDataSet() {
		if (null == sample) {
			Object[][] data = new Object[][] { new String[] { "Sunny", "Hot", "High", "Weak", "No" },
					new String[] { "Sunny", "Hot", "High", "Strong", "No" }, new String[] { "Overcast", "Hot", "High", "Weak", "Yes" },
					new String[] { "Rain", "Mild", "High", "Weak", "Yes" }, new String[] { "Rain", "Cool", "Normal", "Weak", "Yes" },
					new String[] { "Rain", "Cool", "Normal", "Strong", "No" }, new String[] { "Overcast", "Cool", "Normal", "Strong", "Yes" },
					new String[] { "Sunny", "Mild", "High", "Weak", "No" }, new String[] { "Sunny", "Cool", "Normal", "Weak", "Yes" },
					new String[] { "Rain", "Mild", "Normal", "Weak", "Yes" }, new String[] { "Sunny", "Mild", "Normal", "Strong", "Yes" },
					new String[] { "Overcast", "Mild", "High", "Strong", "Yes" }, new String[] { "Overcast", "Hot", "Normal", "Weak", "Yes" },
					new String[] { "Rain", "Mild", "High", "Strong", "No" }, };
			String[] attrs = { "Outlook", "Temperature", "Humidity", "Wind", "Play ball" };
			sample = new ArrayDataSet(data, attrs, 4);
		}
		return sample;
	}

	public ArrayDataSet(Object[][] dataSet, String[] attributes, int classAttrIndex) {
		this.dataSet = dataSet;
		this.attributes = attributes;
		this.classAttrIndex = classAttrIndex;
	}

	public int getClassAttributeIndex() {
		return this.classAttrIndex;
	}

	public int getAttributeCount() {
		return this.attributes.length;
	}

	public String getAttribute(int index) {
		return this.attributes[index];
	}

	public int getAttributeIndex(String attr) {
		for (int i = 0; i < this.attributes.length; i++)
			if (this.attributes[i].equalsIgnoreCase(attr))
				return i;
		return -1;
	}

	// data
	public int getColumnCount() {
		return this.dataSet[0].length;
	}

	public int getRowCount() {
		return this.dataSet.length;
	}

	public Object getValue(int row, int column) {
		return this.dataSet[row][column];
	}

	public Object[] getRow(int row) {
		return this.dataSet[row];
	}

	public Object[][] getData() {
		return this.dataSet;
	}
}
